#!/bin/sh
# Environment
# _TOMCAT_CATALINA_HOME
# _TOMCAT_CATALINA_BASE
# _TOMCAT_CATALINA_OPTS
# _TOMCAT_JAVA_HOME
# _TOMCAT_JAVA_OPTS
# _TOMCAT_VERSION
#

_TOMCAT_VERSION="${_TOMCAT_VERSION:-$_tomcat_default_version}"

_TOMCAT_CATALINA_HOME="${_TOMCAT_CATALINA_HOME:-${DEV_DIR}/apache-tomcat-${_TOMCAT_VERSION}}"
_TOMCAT_CATALINA_BASE="${_TOMCAT_CATALINA_BASE:-${_TOMCAT_CATALINA_HOME}}"
_TOMCAT_JAVA_HOME="${_TOMCAT_JAVA_HOME:-${JAVA_HOME}}"
_TOMCAT_JAVA_HOME="${_TOMCAT_JAVA_HOME:-/usr}"

_TOMCAT_JAVA_OPTS="${_TOMCAT_JAVA_OPTS:-${JAVA_OPTS}}"
_TOMCAT_JAVA_OPTS="${_TOMCAT_JAVA_OPTS:--server}"
_TOMCAT_CATALINA_OPTS="${_TOMCAT_CATALINA_OPTS:--Xms768m -Xmx768m -XX:PermSize=128m -XX:MaxPermSize=256m -XX:NewSize=192m -XX:MaxNewSize=384m}"

if [ ! -r "${_TOMCAT_CATALINA_HOME}/bin/catalina.sh" ]; then
  echo 'Tomcat not found'
fi

CATALINA_HOME="${_TOMCAT_CATALINA_HOME}"
CATALINA_BASE="${_TOMCAT_CATALINA_BASE}"
CATALINA_OPTS="${_TOMCAT_CATALINA_OPTS}"
JRE_HOME=$JAVA_HOME
JAVA_OPTS="${_TOMCAT_JAVA_OPTS}"
PATH="${DEV_HOME}/lib/tomcat:${CATALINA_HOME}/bin:${PATH}"

export INSTANCE_NAME=tomcat_$DEV_TAG
export CATALINA_PID=$CATALINA_BASE/$INSTANCE_NAME.pid
export TOMCAT_USER=`id -un`
export TOMCAT_GROUP=`id -gn`

$DEV_CLEAN && unset _TOMCAT_CATALINA_HOME _TOMCAT_CATALINA_BASE _TOMCAT_CATALINA_OPTS _TOMCAT_JAVA_HOME _TOMCAT_JAVA_OPTS

export CATALINA_HOME
export CATALINA_BASE
export CATALINA_OPTS
export JRE_HOME
export JAVA_HOME
export JAVA_OPTS
